package org.yjc.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.yjc.entity.Teacher;
import org.yjc.service.TeacherService;

@Controller
@RequestMapping(value="/teacher")
public class TeacherController {
	@Autowired
	private TeacherService teacherservice;
	
	@RequestMapping(value="/teachermain")
	public String main(ModelMap map) {
		map.put("teacher", teacherservice.findAll());
		return "teacher/teachermain";
	}
	
	@RequestMapping(value="/changepwd1")
	public String changepwd1(){
		return "teacher/changepwd";
	}
	
	@RequestMapping(value="/changepwd")
	public String changepwd(HttpSession session,String pwd1) {
		Teacher teacher = (Teacher) session.getAttribute("teacher");
		Integer id = teacher.getId();
		Teacher teacher2 = teacherservice.findById(id);
		teacher2.setPassWord(pwd1);
		teacherservice.save(teacher2);
		session.removeAttribute("teacher");
		return "redirect:../login";
	}
	
	@RequestMapping(value="/zhuxiao")
	public String zhuxiao(HttpSession session) {
		Teacher teacher = (Teacher) session.getAttribute("teacher");
		session.removeAttribute("teacher");
		return "redirect:../login";
	}
}
